package com.haierCamera.customapplication.ui.main;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.haierCamera.customapplication.BaseActivity;
import com.haierCamera.customapplication.R;
import com.haierCamera.customapplication.databinding.HzklActivityDeviceVersionBinding;
import com.haierCamera.customapplication.ui.business.Business;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;

public class HZKLCameraDeviceVersionActivity extends BaseActivity {

    HzklActivityDeviceVersionBinding binding;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = DataBindingUtil.setContentView(this, R.layout.hzkl_activity_device_version);
        binding.imgReturn.setOnClickListener((v)->{
            finish();
        });

        binding.btnUpgrade.setOnClickListener((v)->{
            upgrade();
        });

        binding.tvOldVersion.setText(getIntent().getStringExtra("old_V"));
        binding.tvNowVersion.setText(getIntent().getStringExtra("new_V"));
    }

    private void upgrade(){
        showLoadingDialog();
        Business.getInstance().upgradeDevice2(getIntent().getStringExtra("devId"),new Handler(){
            @Override
            public void handleMessage(@NonNull Message msg) {
                super.handleMessage(msg);
                dismissLoadingDialog();
                if (msg.what == 0) {

                    Intent intent = new Intent();
                    setResult(RESULT_OK,intent);
                    finish();
                } else {
                    toast("请求失败-" + msg.what);
                }

            }
        });
    }
}
